Data Structures & Algorithms in Kotlin by By Matei Șuică & By Irina Galata & Irina Galata & Matei Șuică

Data Structures & Algorithms in Kotlin by By Matei Șuică & By Irina Galata & Irina Galata & Matei Șuică

Author:By Matei Șuică & By Irina Galata & Irina Galata & Matei Șuică
Language: eng
Format: epub
Publisher: Ray Wenderlich


Prefix matching

The most iconic algorithm for the trie is the prefix-matching algorithm. Write the following at the bottom of Trie:

fun collections(prefix: List<Key>): List<List<Key>> { // 1 var current = root prefix.forEach { element -> val child = current.children[element] ?: return emptyList() current = child } // 2 return collections(prefix, current) }

Here’s how it works:

You start by verifying that the trie contains the prefix. If not, you return an empty list.

After you’ve found the node that marks the end of the prefix, you call a recursive helper method to find all of the sequences after the current node.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.